package com.zoke.dappstore.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zoke.dappstore.R;
import com.zoke.dappstore.model.Dapp;
import com.zoke.dappstore.tools.Tools;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

import me.zhanghai.android.materialratingbar.MaterialRatingBar;

/**
 * Created by wulijie on 2018/6/8.
 */
public class DappAdapter extends BaseQuickAdapter<Dapp, BaseViewHolder> {

    private boolean isRank;

    public DappAdapter(@Nullable List<Dapp> data) {
        super(R.layout.item_dapp, data);
    }

    public void setRank(boolean isRank) {
        this.isRank = isRank;
    }

    @Override
    protected void convert(BaseViewHolder helper, Dapp item) {
        String typeName;
        switch (item.type) {
            case 1:
                typeName = "应用";
                break;
            case 2:
                typeName = "游戏";
                break;
            default:
                typeName = "其他";
                break;
        }
        if (!TextUtils.isEmpty(item.subType)) {
            typeName = item.subType;
        }
        String des = TextUtils.isEmpty(item.subname) ? "这作者很懒什么也没有留下" : item.subname;
        MaterialRatingBar mrb = helper.getView(R.id.rb);
        ImageView imageView = helper.getView(R.id.headIv);
        ImageOptions options = new ImageOptions.Builder()
                .setRadius(20)
                .build();
        x.image().bind(imageView, item.icon, options);
        helper.setText(R.id.tv_title, item.name)
                .setText(R.id.tv_zh, des)
                .setText(R.id.tv_size, typeName + " | " + Tools.formatSize(item.size))
                .setGone(R.id.tv_position, isRank)
                .setText(R.id.tv_position, String.valueOf(helper.getAdapterPosition() + 1));
        mrb.setNumStars(5);
        mrb.setProgress(item.score * 2);//十分总分
        mrb.setIsIndicator(true);
    }
}
